<?php
/**
 * SKU价格采集数据 Model
 *
 * PHP Version 5
 *
 * @package    Ecga
 * @subpackage Models
 * @author     FarmerLi <lixu_01@126.com>
 * @copyright  2010 Xingchangxinda Inc.
 * @version    SVN:$Id: projects.php 3051 2011-01-11 13:06:18Z sunbo $
 */

namespace Project\Apps\Ecga\Models;

use \Project\Models\Abstraction\Ecga\SkuPriceLogs as bizSkuPriceLogs;

/**
 * SKU价格采集数据 Model
 *
 * PHP version 5
 *
 * @package   Ecga
 * @author    FarmerLi <lixu_01@126.com>
 * @copyright 2010 Xingchangxinda Inc.
 * @version   Release: 0.1
 */
class SkuPriceLogs extends bizSkuPriceLogs
{
    
    /**
     * 按项目取
     * 
     * @param int    $projectId 项目ID
     * @param string $date      日期
     * @param string $batchNo   批次
     * 
     * @return iterator
     */
    public function getByProjectId($projectId, $date, $batchNo)
    {
        $return = $this->select()
            ->where('projectId', '=', $projectId)
            ->where('logDatetime', '=', $date)
            ->where('batchNo', '=', $batchNo)
            ->fetch();
        return $return;
    }

    /**
     * 按项目和渠道取
     * 
     * @param int    $projectId  项目ID
     * @param int    $siteId     渠道ID
     * @param string $date       日期
     * @param string $batchNo    批次
	 * @param array  $productIds sku的数组
     * 
     * @return iterator
     */
    public function getByProjectIdAndSiteId($projectId, $siteId, $date, $batchNo, $productIds)
    {
        $return = $this->select()
            ->where('projectId', '=', $projectId)
            ->where('logDatetime', '=', $date)
            ->where('batchNo', '=', $batchNo)
            ->where('siteId', '=', $siteId);
        if (count($productIds) > 0) {
            $return = $return->where('sku', 'in', $productIds);
        }
        $return = $return->fetch();
        return $return;
    }

    /**
     * 按SKU取
     * 
     * @param string $sku       SKU
     * @param int    $projectId 项目ID
     * @param string $date      日期
     * @param string $batchNo   批次
     * @param int    $siteId    渠道ID
     * 
     * @return int
     */
    public function getBySku($sku, $projectId, $date, $batchNo, $siteId)
    {
        $return = $this->select('price')
            ->where('sku', '=', $sku)
            ->where('projectId', '=', $projectId)
            ->where('logDatetime', '=', $date)
            ->where('batchNo', '=', $batchNo)
            ->where('siteId', '=', $siteId)
            ->fetch()->current();
        return $return['price'];
    }
}